/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package InternetHax;

import InternetHax.App;
import java.util.Vector;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author LoginError
 */
public class Monster extends Actor {
    
    
    private Vector inventory;    //private short HP = 0;
    private short damageReduction = 0;
    private short damageReductionPercent = 0;
    private short attackBonus = 0;
    private short attackBonusPercent = 0;
    public int monsterID = 0;

    public Monster(Sprite thesprite, int HP, int HPMax) {
        super(thesprite);
        inventory = new Vector();
    }
    
    public void takeTurn() {
            super.takeTurn();
            AP = APRecovery;
            //if the player can't see you, you cant see the player, so wander aimlessly
            if (!Toolbox.canPlayerSeeTile(getTilePosition())) {
                
                move(Gamestate.generator.nextInt(4)); //move in a random direction
                Toolbox.printDebug(this.name+": Wandering aimlessly",1);
            }
            
            else {
                //go through each app in the monster's inventory and use it if able, as soon as the 
                
                for (int i = 0; i < inventory.size(); i++) {
                    App app = (App)inventory.elementAt(i);
                            
                    Toolbox.printDebug(this.name+": Trying to use app with id "+ app.getAppID(),1);
                    
                    Gamestate.appManager.useApp(this, app,i);
                    //if the monster has used all of its action points, end it's turn.
                    if(this.AP <= 0)
                        return;
                }
                //move(Toolbox.directionToTile4(getTilePosition(), Gamestate.theHero.getTilePosition()));
            //TODO: change the pathfinder to have a whatTileShouldIMoveTo sort of method.
                Vector thePath = Gamestate.theMap.getPath(false,false, getTilePosition(),Gamestate.theHero.getTilePosition());
                if(thePath.size() > 0)
                {
                    int direction = Toolbox.directionToTile4(getTilePosition(), (Point2d)thePath.elementAt(thePath.size()-1));
                    Toolbox.printDebug(this.name + ": Moving "+ Toolbox.directionToString(direction)+ ".",1);
                    move(direction);
                }
            }
    }

    public void setMonsterID(int monsterID) {
        this.monsterID = monsterID;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getMonsterID() {
        return monsterID;
    }

    public String getName() {
        return name;
    }
    
    public Vector getInventory() {
        return inventory;
    }

    public void setInventory(Vector inventory) {
        this.inventory = inventory;
    }

    public short getDamageReduction() {
        return damageReduction;
    }

    public void setDamageReduction(short damageReduction) {
        this.damageReduction = damageReduction;
    }

    public short getDamageReductionPercent() {
        return damageReductionPercent;
    }

    public void setDamageReductionPercent(short damageReductionPercent) {
        this.damageReductionPercent = damageReductionPercent;
    }

    public short getAttackBonus() {
        return attackBonus;
    }

    public void setAttackBonus(short attackBonus) {
        this.attackBonus = attackBonus;
    }

    public short getAttackBonusPercent() {
        return attackBonusPercent;
    }

    public String toString()
    {
        String info = "MonsterID:" +monsterID +"\nName: "+ name +"\n"+ super.toString()+ "Inventory:\n";
        for (int i = 0; i < inventory.size(); i++) {
            App app = (App) inventory.elementAt(i);
            info += app.toString() + "\n";
        }
        return info;
    }

    public void setAttackBonusPercent(short attackBonusPercent) {
        this.attackBonusPercent = attackBonusPercent;
    }
}
